package org.dream.ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;

import org.dream.imitate.ZhiZunJYPanel;
import org.dream.ui.chart.industry.PercentIndustryChartBuilder;
import org.dream.ui.chart.industry.ValueIndustryChartBuilder;
import org.dream.ui.importui.ImportDaydealPanel;
import org.dream.ui.importui.ImportDealrecordPanel;
import org.dream.ui.importui.ImportDialog;
import org.dream.ui.importui.ImportIndustryPanel;
import org.dream.ui.importui.ImportStockPanel;

/**
 * 
 * 
 * @author qiuriyuchen E-mail:panpan_001@126.com
 */
public class MenuBuilder {
	/**
	 * 设置菜单
	 */
	public static JMenuBar getMenuBar() {
		JMenuBar mBar = new JMenuBar();
		mBar.setOpaque(true);
		mBar.add(MenuBuilder.BuildIndustryAnalysisMenu());// 设置板块分析菜单
		mBar.add(MenuBuilder.BuildStockAnalyzeMenu());// 设置个股分析
		mBar.add(MenuBuilder.buildDealRecordAnalyzeMenu());// 设置我的交易菜单
		mBar.add(MenuBuilder.buildSimulatedTradingMenu());// 交易策略测试
		mBar.add(MenuBuilder.buildToolMenu());// 设置数据

		return mBar;
	}

	/** 行情分析菜单 */
	public static JMenu BuildIndustryAnalysisMenu() {
		JMenu menu = new JMenu();
		menu.setText("板块分析");

		// 板块列表
		JMenuItem stocksMeneItem = new JMenuItem("板块列表");
		stocksMeneItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				MainFrame.getInstanse().setCenterPanel(new IndustryTablePanel(false));
			}
		});
		menu.add(stocksMeneItem);
		// 板块龙头
		JMenuItem longTouMeneItem = new JMenuItem("板块龙头");
		longTouMeneItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				MainFrame.getInstanse().setCenterPanel(new LongTouTablePanel());
			}
		});
		menu.add(longTouMeneItem);
		// 板块走势图
		JMenuItem industryMeneItem = new JMenuItem("板块百分比图");
		industryMeneItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				MainFrame.getInstanse().setCenterPanel(
						new PercentIndustryChartBuilder().buildIndustryChart(null, false));
			}
		});
		menu.add(industryMeneItem);
		// 板块走势图
		JMenuItem industryMeneItem2 = new JMenuItem("板块走势图");
		industryMeneItem2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				MainFrame.getInstanse().setCenterPanel(new ValueIndustryChartBuilder().buildIndustryChart(null, false));
			}
		});
		menu.add(industryMeneItem2);
		// 板块计算列表
		JMenuItem stocksMeneItem2 = new JMenuItem("板块计算列表");
		stocksMeneItem2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				MainFrame.getInstanse().setCenterPanel(new IndustryTablePanel(true));
			}
		});
		menu.add(stocksMeneItem2);

		// 板块计算走势图
		JMenuItem industryMeneItem3 = new JMenuItem("板块计算走势图");
		industryMeneItem3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				MainFrame.getInstanse().setCenterPanel(new ValueIndustryChartBuilder().buildIndustryChart(null, true));
			}
		});
		menu.add(industryMeneItem3);
		return menu;
	}

	/** 行情分析菜单 */
	public static JMenu BuildStockAnalyzeMenu() {
		JMenu menu = new JMenu();
		menu.setText("个股分析");

		// 股票列表
		JMenuItem stocksMeneItem = new JMenuItem("股票列表");
		stocksMeneItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {

				MainFrame.getInstanse().setCenterPanel(StockTablePanel.getJTabbedPane());
			}
		});
		menu.add(stocksMeneItem);
		// 涨停分析
		JMenuItem ztMeneItem = new JMenuItem("涨停分析");
		ztMeneItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {

				MainFrame.getInstanse().setCenterPanel(new ZtTablePanel());
			}
		});
		menu.add(ztMeneItem);

		return menu;
	}

	public static JMenu buildDealRecordAnalyzeMenu() {
		JMenu menu = new JMenu();
		// 导入我的交易记录
		menu.setText("交易记录分析");
		// 查看交易记录
		JMenuItem dealRecordListMenuItem = new JMenuItem("交易查看");
		dealRecordListMenuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				MainFrame.getInstanse().setCenterPanel(new DealRecordPanel());
			}
		});
		menu.add(dealRecordListMenuItem);
		// 我的交易记录
		JMenuItem analyzeMenuItem = new JMenuItem("交易分析");
		analyzeMenuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				MainFrame.getInstanse().setCenterPanel(new DealRecordMoneyFlowPanel());
			}
		});
		menu.add(analyzeMenuItem);
		return menu;

	}

	/**
	 * 创建模拟交易菜单
	 */
	public static JMenu buildSimulatedTradingMenu() {
		JMenu zhizunMenu = new JMenu("实战演习");
		JMenuItem zzjyTestMenuItem = new JMenuItem("止损交易测试");

		zzjyTestMenuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				MainFrame.getInstanse().setCenterPanel(new ZhiZunJYPanel());
			}
		});
		zhizunMenu.add(zzjyTestMenuItem);
		JMenuItem b = new JMenuItem("狙击涨停板");
		zhizunMenu.add(b);
		JMenuItem c = new JMenuItem("K线实战");
		zhizunMenu.add(c);
		return zhizunMenu;

	}

	/**
	 * 创建工具菜单
	 */
	public static JMenu buildToolMenu() {
		JMenu menu = new JMenu("数据导入");
		// 股票导入
		final String importStockTitle = "导入股票信息";
		JMenuItem importStockMI = new JMenuItem("导入股票信息");
		importStockMI.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new ImportDialog(new ImportStockPanel());
			}
		});
		menu.add(importStockMI);
		// 股票导入
		final String importDaydealTitle = "导入行情信息";
		JMenuItem importDaydealMI = new JMenuItem(importDaydealTitle);
		importDaydealMI.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new ImportDialog(new ImportDaydealPanel());
			}
		});
		menu.add(importDaydealMI);
		// 板块导入
		final String importIndustryTitle = "导入板块信息";
		JMenuItem importIndustryMI = new JMenuItem(importIndustryTitle);
		importIndustryMI.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new ImportDialog(new ImportIndustryPanel());
			}
		});
		menu.add(importIndustryMI);
		// 股票交易记录
		final String importDealrecordTitle = "导入交易记录";
		JMenuItem importDealrecordMI = new JMenuItem(importDealrecordTitle);
		importDealrecordMI.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new ImportDialog(new ImportDealrecordPanel());
			}
		});
		menu.add(importDealrecordMI);
		// 清空数据库
		final String clearDbTitle = "清空数据库";
		JMenuItem clearDbMI = new JMenuItem(clearDbTitle);
		clearDbMI.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JOptionPane.showConfirmDialog(null, "确认要清空股票及行情数据库吗", "标题", JOptionPane.YES_NO_OPTION);
			}
		});
		menu.add(clearDbMI);
		return menu;

	}
}
